//1:普通函数二次封装
//请求二次封装思路
//1:统一处理路径，参数，请求方式
//2:请求拦截器
//3:响应拦截器，对服务器返回状态码统一拦截，统一处理
let baseUrl = 'http://localhost:8080'
// let baseUrl = ''
// let baseUrl = 'http://10.212.155.81:8080'
// let baseUrl = '/api'
export default {
	get(url, data) {
		return new Promise((resolve, reject) => {
			uni.request({
				data,
				url: baseUrl + url,
				method: 'get',
				header: {
					"Content-Type": "application/json"
				},
				withCredentials:true,
				success: (data) => {
					//做响应拦截
					resolve(data.data)
				},
				fail: (err) => {
					reject(err)
				}
			})
		})
	},

	post(url, data) {
		return new Promise((resolve, reject) => {
			uni.request({
				data,
				url: baseUrl + url,
				method: 'post',
				header: {
					"Content-Type": "application/json",
				},
				withCredentials:true,
				success: (data) => {
					//做响应拦截

					resolve(data.data)
				},
				fail: (err) => {
					reject(err)
				}
			})
		})
	},
	http({
		url,
		method,
		data
	}) {
		if (method === 'get') {
			this.get(url, data)
		} else {
			this.post(url, data)
		}
	}
}
